package com.example.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> {
    private Integer code;
    private String msg;
    private T data;
    private Integer pageNo;
    private Integer pageSize;
    private Integer pageCount;
    private Integer pageTotal;

    public static final ResponseResult<Void> SUCESS=
            new ResponseResult<>(ResultEnum.SUCESS.getCode(),ResultEnum.SUCESS.getMsg());
    public static final ResponseResult<Void> FAIL=
            new ResponseResult<>(ResultEnum.FAILURE.getCode(), ResultEnum.FAILURE.getMsg());
    public static final ResponseResult<Void> NOLOGIN=
            new ResponseResult<>(ResultEnum.NOLOGIN.getCode(), ResultEnum.NOLOGIN.getMsg());
    public static final ResponseResult<Void> NOAUTH=
            new ResponseResult<>(ResultEnum.NOAUTH.getCode(), ResultEnum.NOAUTH.getMsg());
    public static final ResponseResult<Void> LOGOUT=
            new ResponseResult<>(ResultEnum.LOGOUT.getCode(), ResultEnum.LOGOUT.getMsg());
    public static final ResponseResult<Void> ServerException=
            new ResponseResult<>(ResultEnum.ServerException.getCode(), ResultEnum.ServerException.getMsg());
    //给业务代码统一返回使用

    /**
     * 操作成功
     * @return
     */
    public ResponseResult<T> ok(){
        return new ResponseResult<>(ResultEnum.SUCESS.getCode(), ResultEnum.SUCESS.getMsg());
    }

    /**
     * 查询（操作）成功，并返回数据
     * @param data 查询到的数据(要返回给前端的数据)
     * @return 统一的返回格式
     */
    public ResponseResult<T> ok(T data){
        return new ResponseResult<>(ResultEnum.SUCESS.getCode(),"查询成功",data);
    }

    /**
     * 操作成功，并返回数据和信息
     * @param data 要返回前端的数据
     * @param msg 提示信息
     * @return 统一的返回格式
     */
    public ResponseResult<T> ok(T data,String msg){
        return new ResponseResult<>(ResultEnum.SUCESS.getCode(),msg,data);
    }

    /**
     * 删除成功
     * @param count 删除的数据条数
     * @return 统一的返回格式
     */
    public ResponseResult<T> deleteSuccess(Long count){
        return new ResponseResult<>(ResultEnum.SUCESS.getCode(),"成功删除"+count+"条数据");
    }
    /**
     * 操作失败
     * @return 操作失败的返回消息
     */
    public ResponseResult<T> notok(){
        return new ResponseResult<T>(ResultEnum.NOTOK.getCode(), ResultEnum.NOTOK.getMsg());
    }

    /**
     * 其他失败
     * @param msg 失败提示消息
     * @return 操作失败的返回消息
     */
    public ResponseResult<T> notok(String msg){
        return new ResponseResult<T>(ResultEnum.NOTOK.getCode(),msg);
    }

    /**
     * 查询为空
     * @return 查询为空的返回消息
     */
    public ResponseResult<T> isNull(){
        return new ResponseResult<T>(ResultEnum.ISNULL.getCode(), ResultEnum.ISNULL.getMsg());
    }


    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public ResponseResult(Integer code, String msg, T t){
        this.code = code;
        this.msg = msg;
        this.data = t;
    }
    public ResponseResult(Integer code, String msg, Integer pageNo, Integer pageSize, Integer pageCount, Integer pageTotal, T t){
        this.code = code;
        this.msg = msg;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.pageCount = pageCount;
        this.pageTotal = pageTotal;
        this.data = t;
    }

}
